struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
};

class Solution
{
public:
    int res = 0;
    void InOrder(TreeNode *root, int &k)
    {
        if (root == nullptr)
        {
            return;
        }
        InOrder(root->left, k);
        --k;
        if (k == 0)
        {
            res = root->val;
        }
        InOrder(root->right, k);
    }
    int kthSmallest(TreeNode *root, int k)
    {
        res = 0;
        InOrder(root, k);
        return res;
    }
};
